//注册
Mock.mock("/js/funzc","pson",function(obj){
    let bodyobj=JSON.parse(obj.body);
    let ty=document.querySelectorAll("input[type='checkbox']")[0];
    let yhm=/^[a-zA-Z0-9]{4,15}$/;
    let mm=/^[a-zA-Z0-9]{6,15}$/;
    let yx=/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    if(yhm.test(bodyobj.user)!=true){
        return alert("账号不能为空且账号最低为5个字符数字,字母");
    }else if(yx.test(bodyobj.uyx)!=true){
        return alert("邮箱格式不正确");
    }else if(mm.test(bodyobj.pwd)!=true){
        return alert("密码不能为空且账号最低为6个字符数字,大小写字母");
    }else if(bodyobj.pwd!=bodyobj.qdpwd){
        return alert("两次密码不同");
    }else if(ty.checked!=true){
        return alert("请同意协议");
    }
    
    let zhuce=localStorage.zhuce;
    if(zhuce==undefined || zhuce==null || zhuce==""){
        let arr=[bodyobj];
        localStorage.zhuce=JSON.stringify(arr);
        return true;
    }else{
        let zhuceobj=JSON.parse(zhuce);
        let bool=false;
        for(let i=0;i<zhuceobj.length;i++){
            if(zhuceobj[i].user==bodyobj.user){
                bool=true;
                break;
            }
        }
        if(bool){
            alert("用户名不能重复");
        }else{
            zhuceobj.push(bodyobj);
            localStorage.zhuce=JSON.stringify(zhuceobj);
            return true;
        }
    }
})
//登录
Mock.mock("/js/fundl","pson",function(obj){
    let bodyobj=JSON.parse(obj.body);
    let zhuce=localStorage.zhuce;
    let zhuceobj=JSON.parse(zhuce);
    for(let i=0;i<zhuceobj.length;i++){
        if(zhuceobj[i].user==bodyobj.user || zhuceobj[i].uyx==bodyobj.user && zhuceobj[i].pwd==bodyobj.pwd){
            return true;
        }
    }
})